package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.common.util.AuthUtil;
import com.atguigu.gmall.model.to.UserAuthTo;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/12 3:10
 */
@RestController
@RequestMapping("/api/user")
public class UserAddressController {
    @Autowired
    private UserAddressService userAddressService;

    @PostMapping("/passport/addAddress")
    public Result addAddress(@RequestBody UserAddress userAddress){
        UserAuthTo authTo = AuthUtil.getAuthTo();
        if (authTo.getUserId() == null){
            return Result.build(null,ResultCodeEnum.LOGIN_REQUIRED);
        }
        userAddress.setUserId(authTo.getUserId());
        userAddressService.save(userAddress);
        return Result.ok();
    }
}
